# !/usr/bin/env python
# -*- coding:utf-8 -*-
# project name: CP v1.3.1
# author: "Lei Yong"
# creation time: 2018/4/8 15:16
# Email: leiyong711@163.com

import unittest

from selenium.webdriver.common import keys
from selenium.webdriver.common.keys import Keys
from Operation.element import Element
import time

el = Element()


def login(user, passwd):
    el.openurl('http://192.168.1.190/mayi-Backstage/#/login')
    # el.name('username').clear()
    el.name('username').click()
    el.name('username').send_keys(Keys.CONTROL + 'a')
    el.name('username').send_keys(Keys.BACKSPACE)

    # el.name('password').clear()
    el.name('password').click()
    el.name('password').send_keys(Keys.CONTROL + 'a')
    el.name('password').send_keys(Keys.BACKSPACE)

    el.name('username').send_keys(user)
    el.name('password').send_keys(passwd)
    el.css(".login-button").click()
    # time.sleep(5)



class Test(unittest.TestCase):
    """厅主后台-登录"""

    @classmethod
    def setUpClass(cls):
        cls.driver = el.Driver()

    def test01(self):
        """厅主后台-登录-不填用户名登录"""
        login(user='', passwd='leiyong')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='商户管理平台']", 5), '登录成功')

    def test02(self):
        """厅主后台-登录-不填密码登录"""
        login(user='leiyong', passwd='')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='商户管理平台']", 5), '登录成功')

    def test03(self):
        """厅主后台-登录-账户与密码不匹配登录"""
        login(user='leiyong', passwd='leiy121')
        self.assertFalse(el.trywait_assert_xpath("//span[text()='商户管理平台']", 1), '登录成功')

    def test04(self):
        """厅主后台-登录-账户与密码正常登录"""
        login(user='leiyong', passwd='leiyong')
        self.assertTrue(el.trywait_assert_xpath("//span[text()='商户管理平台']", 5), '登录失败')


    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

